package com.able.concurrency.t1;

import java.util.concurrent.TimeUnit;

/**
 * @author abel.he
 * @data 2018/8/15 20:15
 * @describe
 */
public class Test16_1 {

    volatile int count = 0;

    void add() {
        for (int i = 0; i < 10; i++) {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            count++;
            System.out.println(" 现在的count数量是： " + count);
        }
    }

    int getSize() {
        return this.count;
    }

    void m1(){
        while (true) {
            if (getSize() == 5) {
                System.out.println(getSize() + "结束m1方法");
                break;
            }
        }
    }
    public static void main(String[] args) {
        final Test16_1 test16 = new Test16_1();
        new Thread(new Runnable() {
            public void run() {
                test16.add();
            }
        }).start();

        new Thread(new Runnable() {
            public void run() {
                test16.m1();
            }
        }).start();


    }


}
